package com.four.seckill.config;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class RabbitConfig {

    @Bean
    public Jackson2JsonMessageConverter jackson2JsonMessageConverter(){
        return new Jackson2JsonMessageConverter();
    }

@Autowired
    private RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void initRabbitTemplate(){
        rabbitTemplate.setConfirmCallback((CorrelationData var1, boolean var2, String var3)->{
            System.out.println("confirm...correlationdata["+var1+"]"+"ack==("+var2+")"+"cause==:["+var3+"]");
        });


        rabbitTemplate.setReturnCallback((Message var1, int var2, String var3, String var4, String var5)->{
            System.out.println("Fail Message["+var1+"]==>replyCode["+var2+"]" +
                    "==>replyText["+var3+"]==>exchange["+var4+"]==>routingKey["+var5+"]");
        });

    }

}
